package lc.双指针;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/31
 */
public class Math5_最长回文子串 {

    public String longestPalindrome(String s) {

        String res = "";
        for (int i = 0; i < s.length(); i++) {

            String s1 = expand(s,i,i);
            String s2 = expand(s,i,i + 1);
            res = res.length() > s1.length() ? res : s1;
            res = res.length() > s2.length() ? res : s2;
        }
        return res;

    }
    String expand(String S,int l, int r) {

        while (l >=0 && r < S.length() && S.charAt(l) == S.charAt(r)) {
            l--;
            r++;
        }
        return S.substring(l + 1,r);
    }

}
